﻿// ActionScript file
/**
 * 单选按钮的皮肤�?
 * 
 * author	:com.nickro
 * 
 * USAGE	:
 * 			1、NavButton(Class) extends ListItemSkin{
 * 					override createChildren();
 * 					override overEffect();
 * 					override outEffect();
 * 			as D:\com.nickro\Project\FrameWork\ComponentSkinSample\ActionScriptSkin(NavButton.as)
 * 			2、flash authoring�?use "library",创建继承自ListItemSkin子类的元�?然后通过继承类对元件进行大小，宽度等自适应调整和程序控�?
 * 			TextButton(Class) extends ListItemSkin{
 * 				
 * 			}
 * 			as D:\com.nickro\Project\FrameWork\ComponentSkinSample\FlashSkin(TextButton.as&BaseSkin.fla)
 * 
 */
package org.nickro.skins{
	public class ListItemSkin extends BaseSkin{
		protected var data:Object;
		protected var itemNumber:int;
		private var changed:Boolean=false;
		private var _selected:Boolean=false;
		public function ListItemSkin(){
			super();
		}
		protected function dataType(obj:Object):void{
			if(obj != null){
				try{
					if(obj is String){
						data = obj as String;
					}
					if(obj is Array){
						data = obj as Array;
						itemNumber=data.length;
					}
					
					if(obj is XMLList){
						data = obj as XMLList;
						itemNumber=data.length();
					}
	
					
					if(obj is XML){
						data = obj as XML;
						itemNumber= data.length();
					}
				}catch( e:TypeError){
					throw new TypeError("'dataProvider'的类型不正确");
				}
			}
			createChildren();
		}
		/**创建显示对象*/
		protected function createChildren():void{
			
		}
		/**划过效果*/
		protected function overEffect():void{
			
		}
		/**划出效果*/
		protected function outEffect():void{
			
		}
		override protected function overState():void{
			overEffect();
		}
		override protected function outState():void{
			if(!changed){
				outEffect();
			}
		}
		/**
		 * public setter/getter
		 */
		public function set dataProvider(value:Object):void{
			dataType(value);
		}
		public function get dataProvider():Object{
			return data;
		}
		public function set selected(value:Boolean):void{
			_selected=value;
			if (_selected==false) {
				if(changed){
					outEffect();
					enabled=true;
					mouseEnabled=true;
					changed=false;
				}
			}
			if (_selected==true) {
				changed=true;
				//不需要再一次执行此语句，因为MOUSEOVER已经执行�?
				//overEffect();
				enabled=false;
				mouseEnabled=false;
			}
		}
		public function get selected():Boolean{
			return _selected;
		}
	}
}